﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessInstockGroup
// 文件功能描述：食材入库数据访问层
//
// 
// 创建标识：2012-01-14 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO.WaiGaoQiao;
using System.Data;


namespace Model.WaiGaoQiao
{
    public class OutstockSporadicInfo
    {
        /// <summary>
        /// 自增ID
        /// </summary>
        public int ID
        {
            get;
            set;
        }

        /// <summary>
        /// 领取时间
        /// </summary>
        public DateTime LeanDt
        {
            get;
            set;
        }

        /// <summary>
        /// 零星物品ID
        /// </summary>
        public int GoodsID
        {
            get;
            set;
        }

        /// <summary>
        /// 领取部门
        /// </summary>
        public string LeanDept
        {
            get;
            set;
        }

        /// <summary>
        /// 领取数量
        /// </summary>
        public int LeanCount
        {
            get;
            set;
        }
        /// <summary>
        /// 操作人员
        /// </summary>
        public string Operator_ID
        {
            get;
            set;
        }
        /// <summary>
        /// 记录时间
        /// </summary>
        public DateTime RecordDateTime
        {
            get;
            set;
        }
        /// <summary>
        /// 批号
        /// </summary>
        public string OrderNo
        {
            get;
            set;
        }
        public OutstockSporadicInfo()
        { }

        private DataAccessOutStockSundries outStockAccess;
        private int rowcount = 0;
        public int _rowcount
        {
            get { return rowcount; }
        }

        public OutstockSporadicInfo(bool isgetcount)
        {
            outStockAccess = new DataAccessOutStockSundries();
            if (isgetcount)
            {
                rowcount = GetOutstockGroupSundriesCount("");
            }
        }


        /// <summary>
        /// 零星物品数量
        /// </summary>
        /// <returns></returns>
        public int GetOutstockGroupSundriesCount(string Condition)
        {
            return outStockAccess.GetOutstockGroupCount(Condition);
        }

        public int GetSportadicOutCount(string Condition)
        {
            return outStockAccess.GetSportadicOutCount(Condition);
        }
        /// <summary>
        /// 食材类型数量合计(报表）
        /// </summary>
        /// <returns></returns>
        public int GetOutstockGroupCountBb(string Condition)
        {
            return outStockAccess.GetOutstockGroupCountBb(Condition);
        }
        /// <summary>
        /// 保存零星物品
        /// </summary>
        /// <param name="instginfo"></param>
        /// <returns></returns>
        public int SaveOutstockSundriesGroup(OutstockSporadicInfo outStore)
        {
            object[] igpara = new object[] { outStore.LeanDt,outStore.GoodsID,outStore.LeanDept,outStore.LeanCount,
                                             outStore.Operator_ID, outStore.RecordDateTime,outStore.OrderNo };
            return outStockAccess.SaveOutstockGroup(igpara);
        }

        /// <summary>
        /// 更新零星物品出库
        /// </summary>
        /// <param name="igpara"></param>
        /// <returns></returns>
        public int UpdateInstockSundriesGroup(OutstockSporadicInfo outStore)
        {
            object[] igpara = new object[] { outStore.ID, outStore.LeanDt,outStore.GoodsID,outStore.LeanDept,outStore.LeanCount,
                                             outStore.Operator_ID, outStore.RecordDateTime };
            return outStockAccess.UpdateOutstockGroup(igpara);
        }



        /// <summary>
        /// 获取零星物品出库信息
        /// </summary>
        /// <param name="pagesize">页大小</param>
        /// <param name="startindex">起始页</param>
        /// <param name="dict">查询条件</param>
        /// <returns>食材入库信息</returns>
        public IList<OutstockSporadicInfo> GetOutstockGroupInfo(int pagesize, int startindex, string Condition)
        {
            DataSet ds = outStockAccess.GetOutstockGroup(pagesize, startindex, Condition);
            IList<OutstockSporadicInfo> outHeader = new List<OutstockSporadicInfo>();
            OutstockSporadicInfo SporadicInfo;
            if ((ds != null) && (ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0))
            {
                foreach (DataRow drNew in ds.Tables[0].Rows)
                {
                    SporadicInfo = new OutstockSporadicInfo();
                    SporadicInfo.ID = int.Parse(drNew["ID"].ToString());
                    SporadicInfo.LeanDt = Convert.ToDateTime(drNew[1]);
                    SporadicInfo.GoodsID = Convert.ToInt32(drNew[2]);
                    SporadicInfo.LeanDept = drNew[3].ToString();
                    SporadicInfo.LeanCount = Convert.ToInt32(drNew[4]);
                    SporadicInfo.Operator_ID = drNew[5].ToString();
                    SporadicInfo.RecordDateTime = Convert.ToDateTime(drNew[6]);
                    SporadicInfo.OrderNo = drNew[7].ToString();
                    outHeader.Add(SporadicInfo);
                }

            }
            return outHeader;
        }


        /// <summary>
        /// 获取零星物品出库信息单条
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public OutstockSporadicInfo GetGetOutstockGroupInfo(int Id)
        {
            DataSet ds = outStockAccess.GetOutstockGroup(Id);
            OutstockSporadicInfo SporadicInfo = new OutstockSporadicInfo();
            if (ds != null)
            {
                DataRow drNew = ds.Tables[0].Rows[0];
                SporadicInfo.ID = Convert.ToInt32(drNew[0]);
                SporadicInfo.LeanDt = Convert.ToDateTime(drNew[1]);
                SporadicInfo.GoodsID = Convert.ToInt32(drNew[2]);
                SporadicInfo.LeanDept = drNew[3].ToString();
                SporadicInfo.LeanCount = Convert.ToInt32(drNew[4]);
                SporadicInfo.Operator_ID = drNew[5].ToString();
                SporadicInfo.RecordDateTime = Convert.ToDateTime(drNew[6]);
                SporadicInfo.OrderNo = drNew[7].ToString();
            }
            return SporadicInfo;
        }

        /// <summary>
        /// 删除食材出库
        /// </summary>
        /// <param name="ID">主键</param>
        /// <returns></returns>
        public  int DeleteOutstockGroup(int ID)
        {
            return outStockAccess.DeleteOutstockGroup(ID);
        }

        /// <summary>
        /// 生成批量输入编号
        /// </summary>
        /// <returns></returns>
        public virtual string BuliderOrderNo()
        {
            return outStockAccess.GetOutstockSundiresOrderNo();
        }
        /// <summary>
        /// 食堂零星物品领用表       
        /// </summary>
        /// <returns></returns>
        public DataSet BuilderReportLy(int yy, int mm, string st, int pagesize, int startindex)
        {
            return outStockAccess.BuilderReportLy(yy, mm,st,pagesize,startindex);
        }

        public bool OutStockYzh(int GID, decimal Count)
        {
            return outStockAccess.OutStockYzh(GID, Count);
        }
    }
}
